Today we did some revision of Chapter 1 first and then stepped to the Chapter 2 of java.

Contents in Chapter 1:

1. Storage of numbers
Intergers: -2^31 ~ 2^31-1
Floating-point numbers: sign mantissa*2^exponent
e.g. double 1 52 11
Because of the rounding error, which happens constantly, between the conversion between the binary system used by the computer and the decimal system we human are used to use, we don't use == or != to compare floating-point numbers. Instead, we use the formula: |x − y| ≤ εmax(|x|,|y|) .

2. Cast
Sometimes your want to change the type of your answer, and there are several ways:
For example, the original version is that you get an integer answer 0:
3/4 → int 0
Below there are two valid ways to change your answer into double: whenever one of the numbers is changed to double type, the other will change accordingly so that the final answer is in double:
3.0/4 or 3/4.0 → double 0.75
But watch out, when you turn the whole formula into double, you are turning the answer 0 into 0.0 instead of 0.75, which you are expecting:
(double) (3/4) → double 0.0

3. Operators
There are several types of operators and let's list those below:
a. arithmetic operators: + - * / %
b. relational operatiors: == != > < >= <=
c. logical operators: ! %% ||
d. assignment operators: = += -= *=/= %=
e. Increment and decrement operators: ++ -- (often used in a loop)
Also be aware that there is a precedence of the operators and you may have a look of it in the book.
For the increment and decrement operators specifically, there are some subtle differences between ++a and a++, same as for --. We implemented the operators and had a test of the differences.
import java.util.Scanner;
public class test_increment {
    public static void main(String[]args){
        int a=0;
        ++a;
        System.out.println(a);
        a=0;
        a++;
        System.out.println(a);
        a=0;
        System.out.println(++a);
        a=0;
        System.out.println(a++);
        a=0;
        while(a<6){
            System.out.println(a++);
        }
        a=0;
        while(a<6){
            System.out.println(++a);
        }
    }
}
 
There will be no difference when you do ++a or a++ before printing it, but if you insert it in the line of print, things get complicated:

++a means add first, then print;
a++ means print first, then add;
Especially, be careful when you are using loops: the first loop gives output 0~5 while the second gives 1~6.

4. Selection
if (boolean expression){
}
else if (boolean expression){
}
else{
}

5. Loop
There are three types of ways to write a loop (for/while):
a. for (initiation; terminated condition; update statement)
e.g. for (int i=0; i<10; i++)
b. for (some type element : collection)
e.g. for (int element : arr)
It means we iterate each element in the collection.
c. while (boolean conditions)

Content in Chapter 2:
Objects have both states and behaviors.
Class: very abstract, more like a blueprint, collecting same properties in its objects.
Object = an instance in class

1. Constructor
A constructor always has the same name as the class.
BankAccount n = new BankAccount();

a. a new space of memory is opened
b. n is like a pointer, pointing to the reference of this memory
Overloading:
A default constructor: BankAccount()
Another constructor can be written in same name, but different parameter: BankAccount(parameter)

2. Accessor
Since the static variables are private, we need a method to get the parameters. For example:
public double getBalance(){
        return balance;
    }

3. Scope
Public:
public class: used in any package
public method: used in any class
public variable: used in any class
Private:
private class: used only within this specific packaged
private method: used only within the specific class
private variable: used only within the specific class
Static:
static variable: space of memory is created once each, and it can be used for all objects. They work in a way similar to "global" in python.
static method: uses the class name to call
Instance:
instance variable: only being used while instantiated
instance method: use objects(when instantiated) to call